Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libobs: plugins: Use MAD for sRGB functions #11507

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jpark37
Copy link
Collaborator

@jpark37 jpark37 commented Nov 11, 2024

Description

MAD is faster than ADD then MUL. Also fix stray comment about pow behavior to be accurate.

Motivation and Context

Speed increase is probably nothing to write home about, but I was working on another project in a similar area and figured I might as well address this.

How Has This Been Tested?

  • Step through logic with RenderDoc for libobs/data/color.effect
  • Step through logic with RenderDoc for plugins/obs-filters/data/color.effect
  • Verify text diff for all other files is identical
  • Check Windows OpenGL still works

Types of changes

  • Performance enhancement (non-breaking change which improves efficiency)

Checklist:

  • My code has been run through clang-format.
  • I have read the contributing document.
  • My code is not on the master branch.
  • The code has been tested.
  • All commit messages are properly formatted and commits squashed where appropriate.
  • I have included updates to all appropriate documentation.

Also fix stray comment about pow behavior.
@PatTheMav
Copy link
Member

PatTheMav commented Nov 11, 2024

Just as a quick note: This will make my Metal shader parser just a tad bit more annoying to do, as MSL wants you to write those operations explicitly so the compiler can optimise them itself.

So what would mad(u, 1. / 1.055, .055 / 1.055) be as a standard math expression?

(Supposedly x += m * a should result in the same byte code as x = mad(m,a,x) anyway, but that might not be the case in the specific instructions we use it in?)

@jpark37
Copy link
Collaborator Author

jpark37 commented Nov 11, 2024

We're already using mad in libobs so it's there even without this PR. I added gl_write_mad a while ago to gl-shaderparser.c since fma is not available in GLSL 330.
mad(a, b, c) -> ((a) * (b) + (c))
I use mad explicitly because I've seen at least one GPU driver fail to fuse the operations without the intrinsic.

@PatTheMav
Copy link
Member

We're already using mad in libobs so it's there even without this PR. I added gl_write_mad a while ago to gl-shaderparser.c since fma is not available in GLSL 330. mad(a, b, c) -> ((a) * (b) + (c)) I use mad explicitly because I've seen at least one GPU driver fail to fuse the operations without the intrinsic.

Got it, yeah I'm still torn on whether to simply polyfill HLSL functions in MSL instead of translating them - looks like I already implemented it but for 3 arguments at most:

https://github.com/PatTheMav/obs-studio/blob/e482e1a86250fad3ca85d407741a11949f719621/libobs-metal/OBSShaderParser.swift#L944

@WizardCM WizardCM added the Enhancement Improvement to existing functionality label Nov 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Improvement to existing functionality
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

4 participants